package com.example.gatewayservice;

import org.junit.Test;

public class test {
    @Test
    public void tt() {
        String url = "http://localhost/teacher/ai/test";

        // 步骤 1：去掉协议和主机部分，获取路径
        int firstSlashIndex = url.indexOf('/');
        String pathPart = (firstSlashIndex != -1) ? url.substring(firstSlashIndex) : "";

        // 步骤 2：按 '/' 分割路径
        String[] segments = pathPart.split("/");

        // 步骤 3：提取第1、2个非空段
        String part1 = null;
        String part2 = null;

        int count = 0;
        for (String seg : segments) {
            if (seg.isEmpty()) continue;
            if (count == 0) part1 = seg;
            else if (count == 1) part2 = seg;
            count++;
        }

        // 输出结果
        System.out.println("Part1: " + part1); // teaher
        System.out.println("Part2: " + part2); // ai
    }

}
